import { login } from '@/api/user'
import { getToken, setToken } from '@/utils/auth'
const getDefaultState = () => {
  return {
    token: getToken()
  }
}

const state = getDefaultState()

const mutations = {
  SET_TOKEN: (state, token) => {
    state.token = token
    setToken(token)
  }
}

const actions = {
  // user login
  async login({ commit }, userInfo) {
    const token = await login(userInfo)
    commit('SET_TOKEN', token)
  }

  // get user info

  // user logout

  // remove token
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

